package com.iemes.controller.craft;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

import javax.inject.Inject;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import com.iemes.annotation.SystemLog;
import com.iemes.controller.index.BaseController;
import com.iemes.entity.BrandFormMap;
import com.iemes.entity.BrandModelFormMap;
import com.iemes.entity.ClientFormMap;
import com.iemes.entity.InspectionFormMap;
import com.iemes.entity.ProcessTestFormMap;
import com.iemes.entity.ShapeMachineFormTypeMap;
import com.iemes.entity.TechnoParameterFormMap;
import com.iemes.entity.TechnoSettingFormMap;
import com.iemes.entity.TechnologyFormMap;
import com.iemes.entity.UserFormMap;
import com.iemes.mapper.craft.InspectionMapper;
import com.iemes.plugin.PageView;
import com.iemes.util.Common;
@Controller
@RequestMapping("inspection")
public class InspectionController extends BaseController{
	@Inject
	private InspectionMapper inspectionMapper;
	
	@RequestMapping(value = "patrols", method = RequestMethod.GET, produces = "text/html; charset=utf-8")
	public String examinepru(Model model) {
		return Common.BACKGROUND_PATH + "/technology/inspection/inspection_list";
	}
	
	@ResponseBody
	@RequestMapping("patrol_findByPage")
	public PageView findByPage(String pageNow, String pageSize) {
		InspectionFormMap inspectionFormMap =getFormMap(InspectionFormMap.class);
		HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder
				.getRequestAttributes()).getRequest();
		inspectionFormMap.put("status", 1);
		if (request.getSession().getAttribute("nameId")==null) {
			List<Map<String,Object>> map = new ArrayList<>();
			try {
				LuogicPaging(pageNow,pageSize,map);
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			return pageView;
		}
		inspectionFormMap.put("Machine_ID", request.getSession().getAttribute("nameId"));
		List<Map<String,Object>> listInspection = inspectionMapper.getListInspection(inspectionFormMap);
		Integer nameId  = Integer.parseInt(request.getSession().getAttribute("nameId").toString());
		Map<String,Object> listTable = inspectionMapper.getListTable(nameId);
		if (Integer.parseInt(listTable.get("实际周期"+nameId).toString())> Integer.parseInt(listTable.get("工艺周期"+nameId).toString())) {
			listInspection.get(listInspection.size()-1).put("Violations_One", "<div class=\"circle\"></span>");
		}
		UserFormMap userFormMap = (UserFormMap) Common.findUserSession(request);
		listInspection.get(listInspection.size()-1).put("Thecrew", userFormMap.get("userName"));
		try {
			LuogicPaging(pageNow,pageSize,listInspection);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return pageView;
	}
	

}
